<?php

namespace app\helps;
use app\facade\Redis;
use think\Db;

/**
 * 奖金(团队/直推)操作记录表
 * Class MoneyBonusHelper
 * @package app\helps
 */
class MoneyContractHelper extends MoneyHelperBaser{

    /**
     * 发放合约收益的
     * @param $user 发放收益用户
     * @param $num  数量
     * @param $msg 备注
     */
    public function contractProfit($user,$num,$msg){
        $type = self::TYPE_CONTRACT;
        $op_type =self::OP_TYPE_CONTRACT_PROFIT;
        $res = $this->addUserMoneyAndRecord($user,$num,self::FILED_CONTRACT_COME,$msg,$type,$op_type,0);
        if ($res!=1){
            return $res;
        }
        return 1;
    }

    /**
     * 合约收益兑换商品
     * @param $user 发放收益用户
     * @param $num  数量
     * @param $msg 备注
     */
    public function contract2Goods($user,$num,$goods){
        $type = self::TYPE_CONTRACT;
        $op_type =self::OP_TYPE_CONTRACT_TO_GOODS;
        $msg="用户用合约收益购买商品:".$goods["name"];
        $res = $this->reduceUserMoneyAndRecord($user,$num,self::FILED_CONTRACT_COME,$msg,$type,$op_type,0);
        if ($res!=1){
            return $res;
        }
        return 1;
    }

    /**
     * 合约收益兑换兑换券
     * @param $user 发放收益用户
     * @param $num  数量
     * @param $volume 备注
     */
    public function contract2Volume($user,$contract_come,$volume){
        $type = self::TYPE_CONTRACT;
        $op_type =self::OP_TYPE_CONTRACT_TO_VOLUME;
        $msg="用户用合约收益".$contract_come."兑换".$volume."兑换券";
        $res = $this->reduceUserMoneyAndRecord($user,$contract_come,self::FILED_CONTRACT_COME,$msg,$type,$op_type,0);
        if ($res!=1){
            return $res;
        }
        $type = self::TYPE_VOLUME;
        $op_type =self::OP_TYPE_VOLUME_FROM_CONTRACT;
        $msg="用户用合约收益".$contract_come."兑换".$volume."兑换券";
        $res = $this->addUserMoneyAndRecord($user,$volume,self::FILED_VOLUME,$msg,$type,$op_type,0);
        if ($res!=1){
            return $res;
        }
        return 1;
    }




}